'''
Created on Jan 19, 2010

@author: madsk
'''

from PyQt4 import QtGui, QtCore

class Mediator(QtCore.QObject):
    clicked = QtCore.pyqtSignal()

    def __init__(self):
        super(Mediator, self).__init__()


class GraphicsScene(QtGui.QGraphicsScene):
    def __init__(self, parent=None):
        QtGui.QGraphicsScene.__init__(self, parent)
        self._mediator = Mediator()

        # Set scene properties.
        self.setBackgroundBrush(QtGui.QBrush(QtGui.QColor(0,0,0)))
        
    def mousePressEvent(self, event):
        # Handle the event if no buttons were pressed.
        item = self.itemAt(event.scenePos())
        if item == None or type(item) == QtGui.QGraphicsPixmapItem:
            # There is no button in front of this position.
            self.clicked.emit()
        else:
            # Pass on the event.
            QtGui.QGraphicsScene.mousePressEvent(self, event)

    def clicked(): #@NoSelf
        def fget(self):
            return self._mediator.clicked
        return locals()
    clicked = property(**clicked())